home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
5
/
CHASSIS_
/
MENUPROC.C
< prev
next >
Wrap
Text File
|
1992-05-14
|
9KB
|
288 lines
/************************************************************************************/
/* MenuProc */
/* This proc is entered either from the MouseDownProc with the inMenuBar */
/* condition, or from the KeyDownProc when the Command key has been pressed, */
/* which simulates a mouseDown on the menu, or from a call before the main event */
/* loop if the finder is passing the names of files to be opened or printed upon */
/* startup. */
/************************************************************************************/
#include "MyHeaders.h"
int MenuProc(long menuLong)
{
int MenuRetCode = 0;
long workLong;
int windSubSave;
mymenuID = HiWord(menuLong);
mymenuItem = LoWord(menuLong);
switch (mymenuID)
{
case (AppleMenuID): /* If in Apple Menu... */
switch (mymenuItem)
{
case (AboutItem): /* ...About */
WorkRetCode = ShowInfoDlog (128);
break; /* end of About */
case (HelpItem): /* ...Help */
WorkRetCode = HelpGetProc();
break; /* end of Help */
default: /* ...Desk Accessories */
GetItem(myMenuHandle[0], mymenuItem, &menuItemName);
OpenDeskAcc(menuItemName);
break; /* end of Desk Accessories */
}
break; /* end of Apple Menu */
case (FileMenuID): /* If in File Menu... */
switch (mymenuItem)
{
case (NewItem):
WorkRetCode = TextGetProc();
break;
case (OpenItem):
WorkRetCode = FileOpenProc(); /* open the file */
if (WorkRetCode == 0)
{
WorkRetCode = GetEOF (workPathRefNum, &worklong);
if (WorkRetCode == noErr)
{
if (worklong <= 32767) /* check for max length */
{
WorkRetCode = TextGetProc(); /* open a window */
if (WorkRetCode == 0)
{
SetWTitle (windTbl[windSub].windPtr, /* title */
workReply.fName);
windTbl[windSub].windReply = /* store it */
workReply;
windTbl[windSub].windPathRefNum = /* store it */
workPathRefNum;
worklong = /* read in */
ReadIntoTE(workPathRefNum,
windTbl[windSub].windTEH[0]);
}
else /* window not avail */
MenuRetCode = 1; /* set high ret cod */
}
else /* file too large */
{
ParamText (&workReply.fName,"","",""); /* set name */
PlaceAlert (135); /* position the alert */
StopAlert (135, NIL); /* show the alert */
MenuRetCode = 1; /* set high ret code */
}
}
else /* bad read of EOF */
{
ParamText (&workReply.fName,"","",""); /* set name */
PlaceAlert (136); /* position the alert */
StopAlert (136, NIL); /* show the alert */
MenuRetCode = 1; /* set high ret code */
}
}
else /* other failed to open */
MenuRetCode = 1; /* set high ret code */
windTbl[windSub].windTEChanged = FALSE; /* initialize */
break;
case (SaveItem):
WorkRetCode = FileSaveProc(FALSE); /* save */
if ((WorkRetCode != 0) /* if not good */
&& (WorkRetCode != 2)) /* and not cancel */
{
ParamText (&workReply.fName,"","",""); /* set name */
PlaceAlert (137); /* position the alert */
StopAlert (137, NIL); /* show the alert */
}
else
WorkRetCode = MenuUpdate(ProcText); /* update menus */
break;
case (SaveAsItem):
WorkRetCode = FileSaveProc(TRUE); /* save as */
if ((WorkRetCode != 0) /* if not good */
&& (WorkRetCode != 2)) /* and not cancel */
{
ParamText (&workReply.fName,"","",""); /* set name */
PlaceAlert (137); /* position the alert */
StopAlert (137, NIL); /* show the alert */
}
else
WorkRetCode = MenuUpdate(ProcText); /* update menus */
break;
case (PageSetupItem):
CursorSelect (NIL, NIL, NIL); /* set cursor to arrow */
UseResFile(initResRefNum); /* just manager resfils */
PrStlDialog(prRecHdl); /* run the style dialog */
break;
case (PrintItem):
workBoolean = TRUE; /* initialize */
CursorSelect(NIL, NIL, NIL); /* set arrow cursor */
UseResFile(initResRefNum); /* just manager resfils */
if (PrValidate(prRecHdl)) /* if different printer */
workBoolean = PrStlDialog(prRecHdl); /* run style dialog */
if (workBoolean) /* if still ok */
workBoolean = PrJobDialog(prRecHdl); /* run job dialog */
if (workBoolean) /* if still okay */
PrintWindowProc(windSub); /* go to print */
else /* otherwise */
MenuRetCode = 1; /* set bad return */
break;
case (CloseItem):
workWindowPtr = FrontWindow(); /* which is front (active) ? */
WorkRetCode =
WhichWindow(workWindowPtr, &k); /* match ptr to table */
if (WorkRetCode == 0) /* if it's a good match */
{ /* then */
windSub = k; /* set the subscrpt */
switch (windTbl[windSub].windRec.refCon) /* window type */
{
case (ProcText):
WorkRetCode = TextCloseProc();
break;
case (ProcHelp):
WorkRetCode = HelpCloseProc();
break;
}
}
break;
case (QuitItem): /* ...Quit */
for (j=0; j<windMax; j++) /* check all windows */
{
if (windTbl[j].windRec.refCon == ProcText) /* if text wind */
{
windSubSave = windSub; /* save window sub */
windSub = j;
WorkRetCode = TextCloseProc(); /* close it */
windSub = windSubSave; /* restore wind sub */
if (WorkRetCode != noErr) /* if cancel */
break; /* abort loop */
}
else
if (windTbl[j].windRec.refCon == ProcHelp) /* if help wind */
WorkRetCode = HelpCloseProc(); /* close it */
}
if (j == windMax) /* if we got to the end (no cancel) */
myQuitFlag = 1; /* set the quit flag in event loop */
break; /* end of Quit */
}
break; /* end of File Menu */
case (EditMenuID): /* If in Edit Menu */
workWindowPtr = FrontWindow(); /* which is front (active) ? */
WorkRetCode =
WhichWindow(workWindowPtr, &k); /* match ptr to table */
if (WorkRetCode == 0) /* if it's a good match */
{ /* then */
windSub = k; /* set the subscrpt */
switch (windTbl[windSub].windRec.refCon) /* window type */
{
case (ProcText):
workTEHandle = windTbl[windSub].windTEH[0]; /* get handles */
workControlHandle = windTbl[windSub].windCntlH[0];
switch (mymenuItem)
{
case (CutItem):
TECut(workTEHandle);
myActionProc (workControlHandle, 0);
windTbl[windSub].windTEChanged = TRUE;
worklong = noErr + 1; /* not equal to noErr */
if (ZeroScrap() == noErr)
worklong = TEToScrap();
if (worklong != noErr)
{
worklong = ZeroScrap();
worklong = TEFromScrap();
PlaceAlert (143);
StopAlert (143,NIL);
}
WorkRetCode = MenuUpdate(ProcText);
break;
case (CopyItem):
TECopy(workTEHandle);
myActionProc (workControlHandle, 0);
worklong = noErr + 1; /* not equal to noErr */
if (ZeroScrap() == noErr)
worklong = TEToScrap();
if (worklong != noErr)
{
worklong = ZeroScrap();
worklong = TEFromScrap();
PlaceAlert (143);
StopAlert (143,NIL);
}
WorkRetCode = MenuUpdate(ProcText);
break;
case (PasteItem):
worklong = TEFromScrap();
if (worklong == noErr)
{
if ( (
TEGetScrapLen()
+ (**workTEHandle).teLength
+ (**workTEHandle).selStart
- (**workTEHandle).selEnd
)
> 32767)
{
PlaceAlert (132);
StopAlert (132,NIL);
}
else
TEPaste(workTEHandle);
myActionProc (workControlHandle, 0);
windTbl[windSub].windTEChanged = TRUE;
}
else
{
worklong = ZeroScrap();
worklong = TEFromScrap();
PlaceAlert (143);
StopAlert (143,NIL);
}
WorkRetCode = MenuUpdate(ProcText);
break;
case (ClearItem):
TEDelete (workTEHandle); /* clear */
myActionProc (workControlHandle, 0); /* rescroll */
windTbl[windSub].windTEChanged = TRUE; /* changed */
WorkRetCode = MenuUpdate(ProcText); /* update menus */
break;
}
break;
}
}
break; /* end of Edit Menu */
case (ProgramMenuID): /* If in Program Menu */
switch (mymenuItem)
{
case (KudosItem):
WorkRetCode = ShowInfoDlog (130);
break;
}
break; /* end of Program Menu */
}
HiliteMenu(0); /* turn highlight off */
return MenuRetCode;
}